<!DOCTYPE html>
<html lang='zh-CN'>

<head>
    <meta charset="utf-8">
    <title>test</title>
    <script src="jquery-3.6.0.min.js"></script>
    <script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
</head>

<body>
<button id="testadd" onclick="testadd()">testadd</button>   
<button id="order_add" onclick="order_add()">testadd</button>   
<button id="testupdate" onclick="testupdate()">testupdate</button>   
<br/>
<button onclick="sel_role_all()">selrole</button>   <button onclick="pageadd()">pageadd</button> <button onclick="pagedecre()">pagedecre</button> 
<br/>
<input type="text" name="keyv" id="keyv" value="account" placeholder="keyv"><br/>
<input type="text" name="valv" id="valv" value="16276080023" placeholder="valv"><br/>
<input type="text" name="val_typev" id="val_typev" value="1" placeholder="val_typev"><br/>
<input type="text" name="by_actv" id="by_actv" value="16276080023" placeholder="by_actv"><br/>

<button onclick="sel_act()">selact</button>   
<br/>
<button onclick="update_act()">update_act</button>   
<br/>
<input type="number" name="act" id="act" placeholder="account"><br/>
<input type="text" name="pwd" id="pwd" placeholder="pwd"><br/>
<button onclick="add_act()">addact</button>   
<br/>
<button onclick="test_apk_update()">test_apk_update</button>   
<br/>
<tr>
    <td scope="row">gid</td>
    <td>namename</td>
    <td>ctr</td>
    <td>occ</td>
    <td>level</td>
    <td>ps</td>
    <td>hpbox</td>
    <td>mpbox</td>
    <td>defence</td>
    <td>jz</td>
    <td>yl</td>
    <td>task_cur</td>
    <td>state</td>
    <td>opr</td>
</tr>
<table class="table">

    <tbody id="tbd">
        <tr>
            <td scope="row">game_id</td>
            <td>name</td>
            <td>level</td>
            <td>phy_str</td>
            <td>task_cur</td>
            <td>state</td>
            <td>pos_cur</td>
            <td>操作</td>
        </tr>



    </tbody>
</table>
</body>
<script>

// value_a=6,p_a=0x7ffd03c5e220
// id = 267
// game_id = 4885
// name = 水晶连击
// server = 金玉满堂
// gender = 0
// level = 30
// contri = null
// occupation = null
// jz = null
// yl = null
// exp_cur = null
// exp_max = null
// reli_sect = null
// phy_str = 0
// hp_cur = 0
// hp_max = 0
// mp_cur = 0
// mp_max = 0
// ad = 0
// ap = 0
// defence = 0
// speed = 0
// info_visible = 1
// hp_box = null
// mp_box = null
// skill_list = null
// skill_ex_list = null
// skill_uni = null
// defence_ex_list = null
// combat_cap_list = null
// bag_id = 0
// steed = null
// friends_game_ids = null
// booth_list = null
// pos_cur = null
// task_cur = null
// role_daily_task_id = 0
// is_online = 1
// last_online_time = 2023-04-20 15:48:46
// state = wabao_over
// tag = null
// comment = null
// score = 0
    var url = "https://2020cn.cn/sgjm_auto_backend/api/role_mgr";
    var url_accountmgr = "https://2020cn.cn/sgjm_auto_backend/api/account_mgr";
    var url_updatemgr = "https://2020cn.cn/sgjm_auto_backend/api/update_mgr";
    var defaultPage = 0;
    function test_apk_update(){
        $.get(url_updatemgr+"?ver=1&package=test&ts=123456",function(data,status){
        console.log(data);
    });
   
   }  
   function pageadd(){
        defaultPage = defaultPage + 5;
        if(defaultPage >= 290){
            defaultPage = 0
        }
        console.log(defaultPage)
   }
   function pagedecre(){
    console.log(defaultPage)
        defaultPage = defaultPage - 5;
        if(defaultPage <= 0){
            defaultPage = 250
        }
   }
    function add_act(){
        var act = $("#act").val();
        var pwd = $("#pwd").val();
        if(act.length ==0 || pwd.length ==0){
            console.log("null")
            return;
        }
        
    $.post(
        url_accountmgr,
        {
            "action": "add",
            "account": act,
            "pwd": pwd,
        },
        function (res) {

           console.log(res);
        }
    );
   }  
   function sel_act(){
        var keyv = $("#keyv").val();
        var valv = $("#valv").val();
        var val_typev = $("#val_typev").val();
         if(keyv.length ==0 || valv.length ==0 || val_typev.length==0){
            console.log("null")
            return;
        }
    $.post(
        url_accountmgr,
        {
            "action": "get",
            "key": keyv,
            "val": valv,
            "val_type": val_typev
        },
        function (res) {

           console.log(res);
        }
    );
   }  

   function sel_role_all(){
       
    $.post(
        url,
        {
            "action": "role_select_cols_offset",
            "cols": "game_id, name, level, contri, occupation, phy_str, hp_box, mp_box, defence, task_cur, state, pos_cur, jz, yl",
            "offset": defaultPage
            
        },
        function (res) {
            console.log(res);
            if(res){
                const resobj = JSON.parse(res);
                $.cookie("role", JSON.stringify(resobj.data), { expires: 7 });
                updateView();
            }
            
          
        }
    );
   }  
    function update_act(){
        var keyv = $("#keyv").val();
        var valv = $("#valv").val();
        var val_typev = $("#val_typev").val();
        var by_actv= $("#by_actv").val();
         if(keyv.length ==0 || valv.length ==0 || val_typev.length==0 ||by_actv.length==0){
            console.log("null")
            return;
        }
    $.post(
        url_accountmgr,
        {
            "action": "update",
            "key": keyv,
            "val": valv,
            "val_type": val_typev,
            "account":by_actv
        },
        function (res) {

           console.log(res);
        }
    );
   }  
    function testupdate(){
          var keyv = $("#keyv").val();
        var valv = $("#valv").val();
        var val_typev = $("#val_typev").val();
        var by_actv= $("#by_actv").val();
    $.post(
        url,
        {
            "action": "role_update_kv_by_gameid",
            "game_id": by_actv,
            "key": keyv,
            "val": valv,
            "val_type": val_typev
        },
        function (res) {

           console.log(res);
        }
    );
   }  
   function testadd(){
    $.post(
        url,
        {
            "action": "role_add",
            "game_id": "3409",
            "name": "RETER",
        },
        function (res) {

           console.log(res);
        }
    );
   }

   function updateView(){
        $("#tbd").children().remove();
       
        var objlist =  JSON.parse($.cookie("role"));
        for (let index = 0; index < objlist.length; index++) {
            //tael and coin don't show

            // <td>name</td>
            // <td>level</td>
            // <td>phy_str</td>
            // <td>task_cur</td>
            // <td>state</td>
            // <td>pos_cur</td>
                var node = $("<tr><td scope='row'>" + objlist[index]["game_id"] + "</td><td>" + objlist[index]["name"]+"</td><td>" + objlist[index]["contri"]+"</td><td>" + objlist[index]["occupation"] +"</td><td>" + objlist[index]["level"] +"</td><td>" + objlist[index]["phy_str"] +"</td><td>" + objlist[index]["hp_box"]+"</td><td>" + objlist[index]["mp_box"]+"</td><td>" + objlist[index]["defence"]+"</td><td>" + objlist[index]["jz"]+"</td><td>" + objlist[index]["yl"]+"</td><td>" + objlist[index]["task_cur"] +"</td><td>" + objlist[index]["state"]+"</td><td>" + objlist[index]["pos_cur"] + "</td><td><button onclick='roleOpr("+objlist[index]["game_id"]+")' "+">opr</button></td> </tr>");
                $("#tbd").append(node);
          
        }
    
          

    }
    $(document).ready(function () {
       
        // $.post(
        //     url,
        //     {
        //         "action": "get_one_by_kv",
        //         "key": "level",
        //         "val": "1",
        //         "val_type": "0"
        //     },
        //     function (res) {

        //        console.log(res);
        //     }
        // );
       // console.log(obj)
      
       // var user_id = $.cookie('user_id');
     /*   $.post(
            url,
            {
                "action": "test",
                "key":"name",
                "val":"三国新人",
                "user_id":"1",
                "val_type":"1"
            },
            function (res) {
                console.log(res);
                const resobj = JSON.parse(res);
               
            }
        );
        */
    });

</script>

</html>